package com.slashvision.im.contact

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import io.openim.android.sdk.OpenIMClient
import io.openim.android.sdk.listener.OnBase
import io.openim.android.sdk.models.ConversationInfo
import io.openim.android.sdk.models.UserInfo

class ContactViewModel: ViewModel() {

    private val mFriendManager = OpenIMClient.getInstance().friendshipManager
    private val mconvManager = OpenIMClient.getInstance().conversationManager

    private val _allFriends: MutableLiveData<List<UserInfo>> = MutableLiveData(listOf())
    val allFriends: LiveData<List<UserInfo>> get() = _allFriends

    fun getAllFriends() {
        mFriendManager.getFriendList(object : OnBase<List<UserInfo>> {
            override fun onError(code: Long, error: String?) {

            }

            override fun onSuccess(data: List<UserInfo>?) {
                data?.let {
                    _allFriends.postValue(it)
                }
            }
        })
    }


    private val _allConv: MutableLiveData<List<ConversationInfo>> = MutableLiveData(listOf())
    val allConv: LiveData<List<ConversationInfo>> get() = _allConv

    fun getAllConv() {
        mconvManager.getAllConversationList(object : OnBase<List<ConversationInfo>> {
            override fun onError(code: Long, error: String?) {
            }

            override fun onSuccess(data: List<ConversationInfo>?) {
                data?.let {
                    (it)
                }
            }
        })
    }


}